問題描述
Thuộc tính chi tiết trong ListView không hiển thị (Details property in ListView not displaying)
I set my list view to details to try and create columns, but the columns will not display. What is blocking the columns from displaying?
Imports System.IO
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Menu
Public Class Jonathan_Roda_P4
Dim TitlesData(21)
Dim BOData(21)
'Clear Button Function
Private Sub ResetClearToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetClearToolStripMenuItem.Click
'Clear Title LV
DispResView.Clear()
'Clear Box Office List
BOList.Items.Clear()
'Resets User Message to default
UsrMsg.Text = "Data Not Loaded"
End Sub
'Help/Instructions Properties
Private Sub InstructionsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles InstructionsToolStripMenuItem.Click
MessageBox.Show("1. Click the 'Load Files' Button" & vbNewLine _
& vbNewLine _
& "2. Select two respective files." & vbNewLine _
& " (Note: Each file must have the same number of lines)" & vbNewLine _
& " (Note: You may only select two files)" & vbNewLine _
& vbNewLine _
& "3. Select the 'Open' button to load your selected files" & vbNewLine _
& vbNewLine _
& "4. The Box Office Lister will now display each file's contents as it appears in the file" & vbNewLine _
& vbNewLine _
& "5. Clicking any of the sort buttons will reorder the displayed content as follows:" & vbNewLine _
& " a) Sort by A‑Z: Sorts the displayed content alphabetically by title" & vbNewLine _
& " b) Sort by Z‑A: Sorts the displayed content in reverse alphabetical order by title" & vbNewLine _
& " c) Sort by 0‑9: Sorts the displayed content in ascending numerical order by Box Office Amount" & vbNewLine _
& " d) Sort by 9‑0: Sorts the displayed content in descending numerical order by Box Office Amount" & vbNewLine _
& vbNewLine _
& "6. Clicking the 'Clear' button will reset the program and require you to select two new files" & vbNewLine _
& vbNewLine _
& "7. Clicking the 'Exit' button will close the program" & vbNewLine _
& vbNewLine _
& "8. TOP THIRD" & vbNewLine _
& " Top Third lists the top 1/3 missions in order of Box Office Amount", "007 Box Office Lister Instructions")
End Sub
'File/Exit Properties
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
'Exit Button Properties
Private Sub ExitBtn_Click(sender As Object, e As EventArgs) Handles ExitBtn.Click
Application.Exit()
End Sub
Private Sub ClearBtn_Click(sender As Object, e As EventArgs) Handles ClearBtn.Click
DispResView.Clear()
UsrMsg.Text = "Data Not Loaded"
End Sub
Private Sub LoadButton_Click(sender As Object, e As EventArgs) Handles LoadButton.Click
With OpenFileDialog1
.CheckPathExists = True
.DefaultExt = "txt"
.Filter = _
"Text files (*.txt)|*.txt"
.Multiselect = True
.RestoreDirectory = True
.Title = "Open"
.ValidateNames = True
DispResView.Clear()
End With
'Resets User Message to default if another message is displayed
UsrMsg.Text = "Data Not Loaded"
'Sets Default folder to Desktop
OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
'OpenFileDialog Properties
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim count As Integer = 0
For Each s As String In OpenFileDialog1.FileNames
Dim sAllData() As String = System.IO.File.ReadAllLines(s)
count = count + 1
Next
For Each openFile As String In OpenFileDialog1.FileNames
Dim getAllData() As String = File.ReadAllLines(openFile)
For i As Integer = 0 To getAllData.Length ‑ 1
DispResView.Items.Add(getAllData(i))
Next
Next
End If
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
End Sub
End Class
參考解法
方法 1:
Have you added all your column headers to ListView.Columns? The ListView will not display more columns than it has headers for.
DispResView.Columns.Add "Name"
DispResView.Columns.Add "Size"
'etc.
Note that if you want the column headers not to be erased, you should be calling DispResview.Items.Clear
instead of DispResView.Clear
.
(by NewProgrammer、j__m)